package com.tucc.hello.leetcode.no1_400.no1_200.no1_20.no11_20.no11;

/**
 * @author tucc
 * @description todo
 * @package com.tucc.hello.leetcode
 * @date 2021/5/20
 **/
public class Solution {

    public int maxArea(int[] height) {
        int max = Integer.MIN_VALUE;
        int l = 0, r = height.length - 1;
        while(l < r){
            int min = Math.min(height[l], height[r]);
            int area = min * (r - l);
            if(area > max){
                max = area;
            }
            if(min == height[l]){
                l ++;
                while(l < r && min >= height[l]){
                    l ++;
                }
            }
            if(min == height[r]){
                r --;
                while(l < r && height[r] <= min){
                    r --;
                }
            }
        }
        return max;
    }
    public static void main(String[] args) {
        Solution solution = new Solution();
        int[] height = {1,8,6,2,5,4,8,3,7};
        System.out.println(solution.maxArea(height));

    }
}
